$(document).ready(function () {
	$("#myOrderList").click(function () {
        location.href = 'myOrderList.html';
    })
    $("#personalInfo").click(function () {
        location.href = 'personalInfo.html';
    })
    $("#recAddress").click(function () {
        location.href = 'recAddress.html';
    })
    $("#userInfo").click(function () {
        location.href = '/user/get';
    })
    $("#myPurchaseTemplate").click(function () {
        location.href = 'myPurchaseTemplate.html';
    })
    $("#myLikeTemplate").click(function () {
        location.href = 'myLikeTemplate.jsp';
    })
    $(".edit-cancel").click(function () {
    	$("#editContent").hide();
    	$("#showContent").show();
    })
    $(".userInfo-toEdit>button").click(function(){
    	$("#showContent").hide();
    	$("#editContent").show();
    });
    
    $(".uploadHeadImg,.editUserInfo-headImg>img").hover(function(){
    	$(".uploadHeadImg").show();
    },function(){
    	$(".uploadHeadImg").hide();
    })
    
    $(".uploadHeadImg").click(function(){
    	$("#headFile").click();
    })
    
    $(".editUserInfo-license-img,.uploadLicenseImg").hover(function(){
    	$(".uploadLicenseImg").show();
    },function(){
    	$(".uploadLicenseImg").hide();
    })
    
    $(".uploadLicenseImg").click(function(){
    	$("#licenseFile").click();
    });
    
  //图片上传前预览
    $("#headFile").change(function(){
        var objUrl = getObjectURL(this.files[0]);
        $("#headImg").attr("src", objUrl);
    });
    
    $("#licenseFile").change(function(){
        var objUrl = getObjectURL(this.files[0]);
        $("#licenseImg").attr("src", objUrl);
        if(objUrl){
        	showAjaxLoad();
        	$.ajaxFileUpload({  
		        //处理文件上传操作的服务器端地址  
		        url:"/user/uploadLicenseImg",
		        secureuri:false,                           //是否启用安全提交,默认为false   
		        fileElementId:'licenseFile',               		//文件选择框的id属性  
		        dataType:'json',                         //服务器返回的格式,可以是json或xml等  
		        success:function(result){ 			//服务器响应成功时的处理函数  
		        	showOkAlertTips(result);
		        },  
		        error:function(){ //服务器响应失败时的处理函数  
		        	showOkAlertTips("上传失败，请稍后再试。")
		        },
		        complete: function(){
		        	removeAjaxLoad();
		        }
		    });
        }
    });
    
  //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
    
    $(".edit-save").click(function () {
    	var inputObject = getValuesByInputName(["contactPhone", "verifice", "email", "workUnit", "realName", "profession", "job"])
    	if(judgeInputValue(inputObject.contactPhone, "phone")) return;
    	if(judgeInputValue(inputObject.email, "email")) return;
    	$(this).attr("disabled", true);
    	delete inputObject.verifice;
    	var updateUserInfoSucFunc = function(data){
    		location.href="/user/get";
    	}
    	var updateUserInfoCompFunc = function(){
    		$(".edit-save").attr("disabled", false);
    	}
    	ajaxByMethod("/user/update", "post", inputObject, updateUserInfoSucFunc, null, updateUserInfoCompFunc);
    })
})